package com.bridgeintelligent.tag.webserver.dim.mgmt.service.report;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.report.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Api(tags = "营运报表接口")
@RestController
@RequestMapping("/api/report")
@AllArgsConstructor
@Slf4j
public class ReportController {

    private ReportService  reportService;

    @ApiOperation(value = "近半年客户画像系统整体使用情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true)
    })
    @GetMapping("/systemUseInfo")
    public ReportRep systemUseInfo(String sortWord) {
        try {
            List<ReportSystemUseInfo> data = reportService.systemUseInfo(sortWord);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年客户画像系统整体使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年各机构客户画像系统使用情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true)
    })
    @GetMapping("/orgUseInfo")
    public ReportRep orgUseInfo(String sortWord,String startTime,String endTime) {
        try {
            List<ReportOrgUseInfo> data = reportService.orgUseInfo(startTime,endTime,sortWord);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年各机构客户画像系统使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "分页-近半年各机构客户画像系统使用情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "orgId", value = "机构ID", required = false),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true)
    })
    @GetMapping("/orgUseInfoPage")
    public ReportRep orgUseInfoPage(String sortWord,String orgId,String startTime,String endTime,Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<ReportOrgUseInfo> data = reportService.orgUseInfoPage(sortWord, orgId, startTime, endTime, pageNum, pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("分页-近半年各机构客户画像系统使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年热门标签排行榜01事实标签02预测标签03规则标签04标签因子05排除事实标签和标签因子")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "dimType", value = "标签类型", required = true),
            @ApiImplicitParam(paramType = "query", name = "secDimType", value = "标签类型", required = true)
    })
    @GetMapping("/hotDimInfo")
    public ReportRep hotDimInfo(String dimType,String secDimType) {
        try {
            List<ReportHotDimInfo> data = reportService.hotDimInfo(dimType,secDimType);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年热门标签排行榜查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年01组合标签个人创建情况02定制标签个人创建情况03标签个人使用情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "selectType", value = "查询类型", required = false),
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = false),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "大小", required = false)
    })
    @GetMapping("/combinationCustomizeInfo")
    public ReportRep combinationCustomizeInfo(String selectType,String sortWord, Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<ReportCombinationCustomizeInfo> data = reportService.combinationBustomizeInfo(selectType,sortWord,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年01组合标签个人创建情况02定制标签个人创建情况03标签个人使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年客群使用情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = false),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "大小", required = false)
    })
    @GetMapping("/customerUseInfo")
    public ReportRep customerUseInfo(String sortWord, Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<ReportCustomerUseInfo> data = reportService.customerUseInfo(sortWord,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年客群使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年个人客群创建情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页数", required = false),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "大小", required = false)
    })
    @GetMapping("/customerCreateInfo")
    public ReportRep customerCreateInfo(String sortWord, Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<ReportCustomerCreateInfo> data = reportService.customerCreateInfo(sortWord,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年个人客群创建情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年客户画像系统功能模块使用情况")
    @ApiImplicitParams({})
    @GetMapping("/systemModelUseInfo")
    public ReportRep systemModelUseInfo() {
        try {
            List<ReportSystemModelUseInfo> dataList = reportService.systemModelUseInfo();
            Map<Integer, ReportSystemModelDetailInfo> dataMap = reportService.modelDetailMaxInfo();
            ReportModel data = new ReportModel().setModelUseList(dataList).setModelDetailMap(dataMap);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近近半年客户画像系统功能模块使用情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "画像系统监控看板统计情况")
    @ApiImplicitParams({})
    @GetMapping("/mointorBordInfo")
    public ReportRep mointorBordInfo() {
        try {
            ReportMonitorBordInfo data = reportService.monitorBordInfo();
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("画像系统监控看板统计情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "查询机构列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "orgName", value = "机构名称", required = false)
    })
    @GetMapping("/orgInfo")
    public ReportRep orgInfo(String orgName) {
        try {
            List<OrgInfo> data = reportService.findOrgList(orgName);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("查询机构列表信息查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年客户画像系统功能模块机构使用明细情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "modelType", value = "模块类型", required = true),
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true)
    })
    @GetMapping("/systemModelDetailInfo")
    public ReportRep systemModelDetailInfo(String modelType,String sortWord) {
        try {
            List<ReportSystemModelDetailInfo> data = reportService.modelDetailInfo(modelType,sortWord);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年客户画像系统功能模块机构使用明细情况查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "模块类型字典表")
    @ApiImplicitParams({})
    @GetMapping("/systemModelTypeInfo")
    public ReportRep systemModelTypeInfo() {
        try {
            List<ReportSystemModelTypeInfo> data = reportService.modelTypeInfo();
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近模块类型字典表查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年某机构用户访问明细")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "orgId", value = "机构ID", required = false),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "排序字段", required = true)
    })
    @GetMapping("/orgUserLogin")
    public ReportRep orgUserLogin(String sortWord,String orgId,String startTime,String endTime,Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<OrgUserLoginModel> data = reportService.orgUserLogin(orgId,sortWord,startTime,endTime,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年某机构用户访问明细查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }

    @ApiOperation(value = "近半年某机构用户客群使用明细")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "orgId", value = "机构ID", required = false),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "排序字段", required = true)
    })
    @GetMapping("/orgUserCustomer")
    public ReportRep orgUserCustomer(String sortWord,String orgId,String startTime,String endTime,Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<OrgUserCustomerModel> data = reportService.orgUserCustomer(orgId,sortWord,startTime,endTime,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年某机构用户客群使用明细查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }


    @ApiOperation(value = "近半年某机构用户标签使用明细")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sortWord", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "orgId", value = "机构ID", required = false),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "排序字段", required = true),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "排序字段", required = true)
    })
    @GetMapping("/orgUserDim")
    public ReportRep orgUserDim(String sortWord,String orgId,String startTime,String endTime,Integer pageNum,Integer pageSize) {
        try {
            pageNum = pageNum == null ? 1 : pageNum;
            pageSize = pageSize == null ? 10 : pageSize;
            ReportPage<OrgUserDimModel> data = reportService.orgUserDim(orgId,sortWord,startTime,endTime,pageNum,pageSize);
            return new ReportRep<>(data, BaseCode.SUCCESS);
        } catch (Exception e) {
            log.info("近半年某机构用户标签使用明细查询失败:"+e);
            return new ReportRep<>(new ArrayList<>(),-1, "查询失败");
        }
    }


}
